package com.shiguiwu.springmybatis.javabase.collect;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description: list集合
 * @author: stone
 * @date: Created by 2021/2/7 12:02
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.collect
 */
@Slf4j
public class ListTest {

    public static void main1(String[] args) {
        List<String> list = new ArrayList<>();
        boolean shiguiwu = list.add("shiguiwu");
        list.add("zhoudongxiu");

        list.add("失效期");

        list.add("12345");
        //随机访问

        list.add("mybatis");

        for (int i = 0; i < 1000; i++) {
            list.add("foo" + i);
        }
        log.error(list.get(1));

        //修改元素 ,返回的旧值
        String ent = list.set(2, "哈哈哈");
        //超过容量会抛异常
        list.add(200,"临时加的！！！！！");

        //删除元素
//        shiguiwu = list.remove("哈哈哈");
//        shiguiwu = list.remove("shiguiwu");

//        String remove = list.remove(1);

        //转化
        Map<String, Integer> collect = list.stream().filter(e -> e.length() > 5).map(e -> e + "pig").collect(Collectors.toMap(e -> e, String::length));
        //遍历

        for (String s : list) {
            System.out.println(s);
        }



        log.error("打印集合：{}", JSONUtil.toJsonStr(list));


    }

    public static void main(String[] args) {
        testLinkList();
    }

    public static void testLinkList() {
        List<String> list1 = new LinkedList<>();
        Deque<String> deque = new LinkedList<>();
        boolean shiguiwu = list1.add("shiguiwu");
        list1.add("shiguiwu");
        list1.add("shiguiwu");
        list1.add("shiguiwu");
        list1.add(3, "hahaha");
        boolean shiguiwu1 = list1.remove("shiguiwu");
        boolean shiguiwu2 = list1.remove("shiguiwu");
        boolean shiguiwu3 = list1.remove("shiguiwu");
        boolean shiguiwu4 = list1.remove("shiguiwu2");
        log.error("打印集合：{}", JSONUtil.toJsonStr(list1));


        boolean shiguiwu5 = deque.add("shiguiwu");
        deque.addFirst("shimingli");
        deque.addLast("99999");

        deque.add("zhoudongxiu");
        //检索
        String peek = deque.peek();
        String s = deque.peekFirst();
        String element = deque.element();


    }

    public static void testHutoolsLists() {
        List<String> empty = ListUtil.empty();
    }




}
